package common.codeGen;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class GenCreateController {
	@Autowired
	private GenService genService;
	
	public String create(GenBean genBean){
		StringBuffer sb = new StringBuffer();
		try {
			String oldtableName = genBean.getTableName().substring(0,1).toLowerCase()+genBean.getTableName().substring(1);
			sb.append("package "+genBean.getPackagePath()+".controller;").append("\n");
			sb.append("\n");
			sb.append("import org.springframework.beans.factory.annotation.Autowired;\n");
			sb.append("import org.apache.log4j.Logger;\n");
			sb.append("import org.springframework.stereotype.Controller;\n");
			sb.append("import org.springframework.web.bind.annotation.RequestMapping;\n");
			sb.append("import "+genBean.getPackagePath()+".service."+genBean.getTableName()+"Service;\n");
			sb.append("\n");
			sb.append("@Controller").append("\n");
			sb.append("@RequestMapping(\"/"+oldtableName+"\")").append("\n");
			sb.append("public class "+genBean.getTableName()+"Controller {").append("\n");
			sb.append("Logger logger = Logger.getLogger(this.getClass());").append("\n");
			sb.append("@Autowired").append("\n");
			sb.append("private "+genBean.getTableName()+"Service "+oldtableName+"Service;").append("\n");
			sb.append("}\n");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sb.toString();
	}
	
}
